package com.weichen.studentgameexchange.member.controller;

import cn.hutool.core.util.StrUtil;
import com.weichen.studentgameexchange.common.common.Result;
import com.weichen.studentgameexchange.member.entity.User;
import com.weichen.studentgameexchange.member.entity.vo.UserPlatformVo;
import com.weichen.studentgameexchange.member.entity.vo.UserVo;
import com.weichen.studentgameexchange.member.service.IGraduationTimeService;
import com.weichen.studentgameexchange.member.service.IRoleService;
import com.weichen.studentgameexchange.member.service.IUserRoleService;
import com.weichen.studentgameexchange.member.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 功能：
 * 作者：惟尘
 * 日期：2025/1/23 10:20
 */
@RestController
public class LoginController {

    @Autowired
    IUserService userService;
    @Autowired
    IUserRoleService userRoleService;
    @Autowired
    IRoleService roleService;
    @Autowired
    IGraduationTimeService graduationTimeService;

    @PostMapping("/login")
    public Result login(@RequestBody User user){
        if (StrUtil.isBlank(user.getUsername())||StrUtil.isBlank(user.getPassword())){
            return Result.error("数据输入不合法！");
        }
        UserPlatformVo login = userService.login(user);
        return Result.success(login);
    }

    //放开权限保护
    @PostMapping("/register")
    public Result register(@RequestBody User user){
        if (StrUtil.isBlank(user.getUsername())||StrUtil.isBlank(user.getPassword())){
            return Result.error("数据输入不合法！");
        }
        userService.register(user);
        User userSetTime = graduationTimeService.register(user);
        userService.save(userSetTime);
        return Result.success();
    }
}
